package com.simplehire.scheduler;

import com.simplehire.repository.UserPermissionRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;

@Component
@RequiredArgsConstructor
public class PermissionCleanupScheduler {

    private final UserPermissionRepository permissionRepository;

    @Scheduled(cron = "0 0 2 * * ?") // 每天凌晨2点执行
    @Transactional
    public void cleanupExpiredPermissions() {
        LocalDateTime now = LocalDateTime.now();
        permissionRepository.deleteExpiredPermissions(now);
    }
}